Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
hast-util-to-string
Advanced tools
The hast-util-to-string package is a utility for converting HAST (Hypertext Abstract Syntax Tree) nodes to plain strings. This is particularly useful when working with virtual DOM representations in projects that involve transforming HTML or Markdown content.
Convert HAST node to string
This feature allows the conversion of a HAST node, which can be a complex structure with nested elements, into a plain string. The code sample demonstrates creating a simple HAST tree using hastscript and then converting it to a string using hast-util-to-string.
const toString = require('hast-util-to-string');
const h = require('hastscript');
const tree = h('div', [h('p', 'Hello, world!')]);
const result = toString(tree);
console.log(result); // Outputs: 'Hello, world!'
Part of the unified.js ecosystem, rehype-stringify converts HAST trees to HTML strings. It is similar to hast-util-to-string but focuses on generating HTML output rather than plain text, making it suitable for different use cases where HTML structure needs to be preserved.
This package converts HAST nodes to MDAST (Markdown Abstract Syntax Tree) nodes. While hast-util-to-string focuses on converting to plain text, hast-util-to-mdast is useful for transformations into Markdown, maintaining markdown-specific formatting and structures.
Get the plain-text value of a hast node.
This package is ESM only:
Node 12+ is needed to use it and it must be imported
ed instead of required
d.
npm:
npm install hast-util-to-string
This package exports the following identifiers:
toString
.
There is no default export.
import {h} from 'hastscript'
import {toString} from 'hast-util-to-string'
toString(h('p', 'Alpha'))
//=> 'Alpha'
toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']))
//=> 'Bold and italic.'
toString(node)
Transform a node to a string.
See contributing.md
in rehypejs/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
hast utility to get the plain-text value of a node
The npm package hast-util-to-string receives a total of 1,870,843 weekly downloads. As such, hast-util-to-string popularity was classified as popular.
We found that hast-util-to-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.